/*
*  Copyright (c) 2018. 玺得（深圳）科技有限公司.保留所有权利. http://www.pi-top.com/ 玺得（深圳）科技有限公司保留所有代码著作权.如有任何疑问请访问官方网站与我们联系. 代码只针对特定需求定制编码，不得在未经允许或授权的情况下对外传播扩散.恶意传播者，法律后果自行承担. 本代码仅用于pps-cloud系统.
*/
package com.pitop.material.service;

import com.pitop.core.entity.Page;
import com.pitop.core.exceptions.BaseException;
import com.pitop.core.exceptions.MaterialSupplierException;
import com.pitop.material.api.MaterialSupplierFeignApi;
import com.pitop.material.entity.MaterialSupplier;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 物料供应商
 *
 * @author berton
 */
@Service("materialSupplierSVImpl")
@Slf4j
public class MaterialSupplierSVImpl {

    @Autowired
    private MaterialSupplierFeignApi materialSupplierFeignApi;

    /**
     * 加载一个对象MaterialSupplier
     *
     * @param id * @param suppierCode 供应商编码* @param materialCode 物料编码
     * @return MaterialSupplier
     */
    public MaterialSupplier load(Long id, String suppierCode, String materialCode) {
        if (id == null && suppierCode == null && materialCode == null) {
            throw new MaterialSupplierException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return materialSupplierFeignApi.load(id, suppierCode, materialCode);
    }

    /**
     * 加载一个对象MaterialSupplier 通过id
     *
     * @param id
     * @return MaterialSupplier
     */
    public MaterialSupplier loadById(Long id) {
        if (id == null) {
            throw new MaterialSupplierException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return materialSupplierFeignApi.loadById(id);
    }

    /**
     * 加载一个对象MaterialSupplier 通过suppierCode
     *
     * @param suppierCode 供应商编码
     * @return MaterialSupplier
     */
    public MaterialSupplier loadBySuppierCode(String suppierCode) {
        if (suppierCode == null) {
            throw new MaterialSupplierException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return materialSupplierFeignApi.loadBySuppierCode(suppierCode);
    }

    /**
     * 加载一个对象MaterialSupplier 通过materialCode
     *
     * @param materialCode 物料编码
     * @return MaterialSupplier
     */
    public MaterialSupplier loadByMaterialCode(String materialCode) {
        if (materialCode == null) {
            throw new MaterialSupplierException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        return materialSupplierFeignApi.loadByMaterialCode(materialCode);
    }


    /**
     * 删除对象MaterialSupplier
     *
     * @param id * @param suppierCode 供应商编码* @param materialCode 物料编码
     */

    public void delete(Long id, String suppierCode, String materialCode) {
        if (id == null && suppierCode == null && materialCode == null) {
            throw new MaterialSupplierException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        materialSupplierFeignApi.delete(id, suppierCode, materialCode);
    }


    /**
     * 查询MaterialSupplier分页
     *
     * @param materialSupplier 对象
     * @param curPage          当前页
     * @param pageSize         分页条数
     * @return List<MaterialSupplier>
     */
    public List<MaterialSupplier> list(MaterialSupplier materialSupplier, int curPage, int pageSize) {
        return materialSupplierFeignApi.list(materialSupplier, curPage, pageSize);
    }

    /**
     * 查询MaterialSupplier分页
     *
     * @param id       * @param suppierCode  供应商编码* @param materialCode  物料编码
     * @param curPage  当前页
     * @param pageSize 分页条数
     * @return List<MaterialSupplier>
     */
    public List<MaterialSupplier> list(Long id, String suppierCode, String materialCode, int curPage, int pageSize) {
        if (curPage < 0) {
            curPage = 1;
        }

        if (pageSize < 0) {
            pageSize = Page.limit;
        }

        MaterialSupplier materialSupplier = new MaterialSupplier();
        materialSupplier.setId(id);
        materialSupplier.setSuppierCode(suppierCode);
        materialSupplier.setMaterialCode(materialCode);

        return materialSupplierFeignApi.list(materialSupplier, curPage, pageSize);
    }


    public int count(Long id, String suppierCode, String materialCode) {
        return materialSupplierFeignApi.count(id, suppierCode, materialCode);
    }


    public int count(MaterialSupplier materialSupplier) {
        return materialSupplierFeignApi.count(materialSupplier);
    }


    /**
     * 保存
     *
     * @param materialSupplier 实体
     * @throws BaseException
     */
    public void save(MaterialSupplier materialSupplier) {
        if (materialSupplier == null) {
            throw new MaterialSupplierException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        materialSupplierFeignApi.build(materialSupplier);
    }

    /**
     * 更新
     *
     * @param materialSupplier 实体
     * @throws BaseException
     */
    public void modify(MaterialSupplier materialSupplier) {
        if (materialSupplier == null) {
            throw new MaterialSupplierException(BaseException.BaseExceptionEnum.Illegal_Param);
        }
        materialSupplierFeignApi.modify(materialSupplier);
    }

}
